#import "Role.h"
Role::Role(const char* ani_file)
{
	m_ID = 0;
	m_ArrID = 0;
	m_Type = 0;
	
	m_speed = 6;//≤æ∞ ≥t´◊
	_speed=m_speed;//≤æ∞ ≥t´◊
	m_baseChangeTime=100;
	m_changeTime=m_baseChangeTime;
	m_iX = 0;
	m_iY = 0;
	m_ActID = 0;//∞ ß@ID
	m_ACTOff = 0;
	m_iActionNum = 0;//∞ ß@º∆∂q
	//m_RoleAction = NULL;
	
	m_TriggerNum = 0;
//	m_strTrigger = NULL;
	playType=3;
	
	//aiAct = NULL;
	
	_tempIndex = 0;
	bAttackAim = 0;//¨Oß_©R§§•ÿº–
	bAttackBack = 0;//ß¿ª®œ§H´·∞h
	bDong = 0;
	
	m_dir = 0;
	
	//__ZERO_ARRAY(_img_name);

//	_img_name = 0;
	
	FILE* fp = fopen(GetResPath(ani_file), "r");
	
	byte imgNum = 0;
	fread(&imgNum, sizeof (byte), 1, fp);
	
//	assert(imgNum == 1);
	
	//read image file name.
	for (int j = 0; j < imgNum; j++){
		
		short string_length = 0;
		fread(&string_length, sizeof (string_length), 1, fp);
		JavaBitReverse(&string_length, sizeof(string_length), 1);
		
		char* imgName = new char[128];
		fread(imgName, string_length, 1, fp);
		// add .png file end;
		int _name_length = string_length;
		char * pName = imgName + string_length;
		*pName = '.';
		*(++pName) = 'p';
		*(++pName) = 'n';
		*(++pName) = 'g';
		*(++pName) = '\0';
		m_imgNameVec.push_back(imgName);
	}
	
	int role_num = 0;
	fread(&role_num, sizeof (role_num), 1, fp);
	JavaBitReverse(&role_num, sizeof(role_num), 1);
	
	
	fseek(fp, sizeof(int), 1);
	loadRole(fp);
	fclose(fp);
}

Role::~Role()
{
	while (m_RoleAction.empty() == false){
		SAFE_DELETE(m_RoleAction.back());
		m_RoleAction.pop_back();
	}
	
	SAFE_DELETE(m_imgRole);
}

void Role::loadRole(FILE* fp){

//	FILE* fp = fopen(GetResPath("role.bin"), "r");
	
	fread( &m_iActionNum, sizeof(byte), 1, fp);
	
      for (int i = 0; i < m_iActionNum; i++) {
		  m_RoleAction.push_back(new Action());
        m_RoleAction.back()->loadFrame(fp);
      }
	
	int _aiNum = 0;
	fread( &_aiNum, sizeof(byte), 1, fp);
	
	aiAct.resize(_aiNum);
 //     aiAct = new byte[_aiNum][];
      for (int i = 0; i < _aiNum; i++) {
			int _arrNum = 0;
		  fread( &_arrNum, sizeof(byte), 1, fp);
		  
		  aiAct[i].resize(_arrNum);
			for (int j = 0; j < _arrNum; j++) {
				byte _v = 0;
				fread( &_v, sizeof(byte), 1, fp);
				aiAct[i][j] = _v;
			}
		}
    
}


Role::Role(const Role& roleS ,int m,int n){
	m_Type=roleS.m_Type;

	m_iActionNum=roleS.m_iActionNum;
	m_speed=_speed=roleS.m_speed;
	// m_RoleAction=new  Action[roleS.m_iActionNum];
	for(int i=0;i< m_iActionNum;i++){
	   m_RoleAction.push_back( new  Action(*(roleS.m_RoleAction[i])));
	}

	aiAct.resize(roleS.aiAct.size());
	for (int i = 0; i <  aiAct.size(); i++) {
	   aiAct[i].resize(roleS.aiAct[i].size());
	   for (int j= 0; j< aiAct[i].size(); j++) {
		 aiAct[i][j]=roleS.aiAct[i][j];
	   }
	}
	m_iX=n*16;
	m_iY=m*16+8;
	playType=roleS.playType;
}









